<template>
	<view class="content">

		<view class="header u-relative">
			<view class="child u-p-l-30 u-p-r-30">
				<IndexUserCard :isLogin="isLogin" @relogin="onRelogin"></IndexUserCard>
			</view>

		</view>
		<template v-for="(item,index) in FilterCardConfig ">
			<view class="body u-p-l-30 u-p-r-30" v-if="item.items.length">
				<IndexCard :isLogin="isLogin" :key="index" :data="item"></IndexCard>
			</view>
		</template>




		<!-- <view style="height:100rpx;"></view> -->

		<u-tabbar :list="tabBarList" :value="1" :before-switch="tabbarBeforeSwitch" active-color="#409eff"
			:mid-button="true">
		</u-tabbar>
		<u-toast ref="uToast" />
		<ScanCodeDialog  ref="ScanCodeDialog" v-model="scanCodeDialogVisble" :code="scanValue"></ScanCodeDialog>
	</view>
</template>

<script>
	import ScanCodeDialog from '@/components/scanCodePopUp/index.vue'
	import PagesProjectRouterConfig from '@/pagesProject/routerConfig.js'
	import PagesDemandRouterConfig from '@/pagesDemand/routerConfig.js'
	import PagesPollingRouterConfig from '@/pagesPolling/routerConfig.js'
	import PagesHuiYiRouterConfig from '@/pagesHuiyi/routerConfig.js'
	import PagesTaskRouterConfig from '@/pagesTask/routerConfig.js'
	import IndexCard from '@/components/card/index/index.vue'
	import IndexUserCard from '@/components/card/index/user.vue'

	import {
		approveRedData,
		getOrderRedData,
		taskRedData
	} from '@/apis/index.js'
	import {
		mathSum
	} from '@/filter/index.js'
	import {
		Factory,
		Hospital,
		Storage_IsFactoryValue
	} from '@/common/index.js'
	import CustomIconFontName from '@/common/customIconFontName.js'
	import {
		tabbarConfig
	} from '@/common/tabbarConfig.js'
	export default {
		components: {
			IndexCard,
			IndexUserCard,
			ScanCodeDialog
		},

		data() {
			return {
				scanValue:'',
				scanCodeDialogVisble: false,
				tabbarIndex: 0,
				tabBarList: tabbarConfig,
				isHxey: false,
				isLogin: false,
				redNumData: {
					//我的工单
					myOrder: 0,
					//工单审核
					orderReview: 0,
					// 需求管理
					demand: 0,
					//项目管理
					project: 0,
					//我的任务
					myTask: 0,

				},
			}
		},

		computed: {
			FilterCardConfig() {
				let filter_arr = this.cardConfig.map((item) => {
					let items = item.items.filter((val) => val.showModuleControl.includes(
						Storage_IsFactoryValue()))

					return {
						title: item.title,
						items: items

					}
				})
				return filter_arr
			},
			cardConfig() {
				return [{
						title: '综合',
						items: [{
							showModuleControl: [Hospital],
							name: CustomIconFontName.WoDePaiBan.label,
							redNum: 0,
							icon: CustomIconFontName.WoDePaiBan.iconName,
							navUrl: '/pagesA/arrange/arrange',
						}, {
							showModuleControl: [Hospital],
							name: CustomIconFontName.WodeRenWu.label,
							redNum: this.redNumData.myTask,
							icon: CustomIconFontName.WodeRenWu.iconName,
							navUrl: PagesTaskRouterConfig.Task
						}, {
							showModuleControl: [Hospital, ],
							name: CustomIconFontName.RenWuTongJi.label,
							redNum: 0,
							icon: CustomIconFontName.RenWuTongJi.iconName,
							navUrl: PagesTaskRouterConfig.Tongji
						}, {
							showModuleControl: [Hospital],
							name: CustomIconFontName.WoDeHuiYi.label,
							redNum: 0,
							icon: CustomIconFontName.WoDeHuiYi.iconName,
							navUrl: PagesHuiYiRouterConfig.Huiyi
						}, {
							showModuleControl: [Hospital],
							name: CustomIconFontName.LiShiHuiYi.label,
							redNum: 0,
							icon: CustomIconFontName.LiShiHuiYi.iconName,
							navUrl: PagesHuiYiRouterConfig.Search
						}]

					},
					{
						title: '报障',
						items: [{
								showModuleControl: [Hospital],
								name: CustomIconFontName.TongHuaJiLu.label,
								redNum: 0,
								icon: CustomIconFontName.TongHuaJiLu.iconName,
								navUrl: '/pagesCallRecords/index'
							}, {
								showModuleControl: [Hospital, Factory],
								name: CustomIconFontName.BaoXiu.label,
								redNum: 0,
								icon: CustomIconFontName.BaoXiu.iconName,
								navUrl: '/pages/index/report'
							}, {
								showModuleControl: [Factory],
								name: CustomIconFontName.SongXiuGuanLi.label,
								redNum: 0,
								icon: CustomIconFontName.SongXiuGuanLi.iconName,
								navUrl: '/sendRepair/factory/index'
							}, {
								showModuleControl: [Hospital],
								name: CustomIconFontName.SongXiuGuanLi.label,
								redNum: 0,
								icon: CustomIconFontName.SongXiuGuanLi.iconName,
								navUrl: '/sendRepair/department/index'
							},
							{
								showModuleControl: [Hospital, Factory],
								name: CustomIconFontName.WodeGongDan.label,
								redNum: this.redNumData.myOrder,
								icon: CustomIconFontName.WodeGongDan.iconName,
								navUrl: '/pages/myOrder/order'
							}, {
								showModuleControl: [Hospital],
								name: CustomIconFontName.GongDanShenHe.label,
								redNum: this.redNumData.orderReview,
								icon: CustomIconFontName.GongDanShenHe.iconName,
								navUrl: '/pages/aduitOrder/order'
							}, {
								showModuleControl: [Hospital, Factory],
								name: CustomIconFontName.LiShiGongDan.label,
								redNum: 0,
								icon: CustomIconFontName.LiShiGongDan.iconName,
								navUrl: '/pages/order/search'
							}
						]
					},
					{
						title: '项目',
						items: [{
							showModuleControl: [Hospital],
							name: CustomIconFontName.XuQiuGuanLi.label,
							redNum: this.redNumData.demand,
							icon: CustomIconFontName.XuQiuGuanLi.iconName,
							navUrl: PagesDemandRouterConfig.Demand
						}, {
							showModuleControl: [Hospital],
							name: CustomIconFontName.WoDeXiangMu.label,
							redNum: this.redNumData.project,
							icon: CustomIconFontName.WoDeXiangMu.iconName,
							navUrl: PagesProjectRouterConfig.Project
						}]
					},
					{
						title: "巡检",
						items: [{
							showModuleControl: [Hospital],
							name: CustomIconFontName.ZiChanXunJian.label,
							redNum: 0,
							icon: CustomIconFontName.ZiChanXunJian.iconName,
							navUrl: PagesPollingRouterConfig.Property
						}, {
							showModuleControl: [Hospital, Factory],
							name: CustomIconFontName.WodeXunJian.label,
							redNum: 0,
							icon: CustomIconFontName.WodeXunJian.iconName,
							navUrl: PagesPollingRouterConfig.Polling
						}, {
							showModuleControl: [Hospital, Factory],
							name: CustomIconFontName.XunJianJiLu.label,
							redNum: 0,
							icon: CustomIconFontName.XunJianJiLu.iconName,
							navUrl: PagesPollingRouterConfig.Search
						}]

					},
					// {
					// 	title: '资产',
					// 	items: [{
					// 		showModuleControl:['hospital'],
					// 		name: '资产巡检',
					// 		redNum: 0,
					// 		icon: require('@/static/images/asset_inspection.png'),
					// 		navUrl: PagesPollingRouterConfig.Property
					// 	}]
					// },
				]
			}
		},

		onLoad(e) {

			if (e.hasOwnProperty('scene')) {
				let scene = e.scene
				setTimeout(() => {
					if (scene) {
						uni.navigateTo({
							url: '/pages/index/report?type=2&scene=' + encodeURI(scene)
						})
					}
				}, 100)

			}
		},
		onUnload() {

		},
		onShow() {
			if (uni.getStorageSync('token')) {
				this.isLogin = true
				this.isHxey = uni.getStorageSync('hxey')
				this.getRedData()
			} else {
				this.isLogin = false
			}

		},
		methods: {
			tabbarBeforeSwitch(index) { 
				if (index === 1) {
				this.$refs.ScanCodeDialog.scanCode()  
				}
				return true
			},
			unlogin() {
				uni.clearStorage()
				this.isLogin = false
			},
			onRelogin() {
				this.getRedData()
			},

			getRedData() {
				approveRedData().then(res => {
					let {
						wait_audit,
						reject,
						pass
					} = res.body
					this.redNumData.orderReview = mathSum([wait_audit, reject, pass])
				})

				getOrderRedData().then(res => {
					let {
						wait_accept,
						processing,
						appraisal,
						not_pass_audit
					} = res.body
					this.redNumData.myOrder = mathSum([wait_accept, processing, appraisal, not_pass_audit])
				})
				taskRedData().then(res => {
					let {
						unProcess,
						audit
					} = res.body
					this.redNumData.myTask = mathSum([unProcess, audit])
				})
			},



		}
	}
</script>
<style lang="scss" scoped>
	.content {
		width: 750rpx;
		overflow: hidden;
	}

	.header {
		background-image: url("@/static/other/index.png");
		background-size: 100% 100%;
		background-repeat: no-repeat;

		height: 450rpx;

		>.child {
			position: absolute;
			width: 100%;
			bottom: 0;
			left: 0;
		}
	}
</style>
